package businessServlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.google.appengine.api.datastore.Text;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
import com.tecnick.htmlutils.htmlentities.HTMLEntities;

import controller.Controller;

@SuppressWarnings("serial")
public class TypesBusiness extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		String bizType = req.getParameter("bizType");
		String langName = (String) req.getSession().getAttribute("lang");
		
		if (langName==null)
		{
			langName="he";			
		}
		
		req.getSession().setAttribute("statusBizType", Controller.getInstance().getStatusOfBizType(bizType,langName));
		PrintWriter out = resp.getWriter();
		StringBuffer sb = new StringBuffer("");
		ArrayList<String> messages = Controller.getInstance().getMessageOfBizType(bizType,langName);
		int index=0;
		for(String message : messages){
			//sb.append("<li id='list_"+status+"'>"+status+"<a href='' onclick='removeItem(list_"+status+"); return false;'>     remove</a></li>");
			out.println("<li id='message1_"+index+"' value='list_"+HTMLEntities.htmlentities(message)+"'>"+HTMLEntities.htmlentities(message).replaceAll("_", " ")+"<a href='' onclick='removeItem(message1_"+index+"); return false;'>     remove</a></li>");
			index++;
		}
		//req.getSession().setAttribute("messageBizType", Controller.getInstance().getMessageOfBizType(bizType));
		
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String bizType = req.getParameter("bizType");
		String langName = (String) req.getSession().getAttribute("lang");
		
		if (langName==null)
		{
			langName="he";			
		}
		
		req.getSession().setAttribute("statusBizType", Controller.getInstance().getStatusOfBizType(bizType,langName));
		PrintWriter out = resp.getWriter();
		//StringBuffer sb = new StringBuffer("");
		ArrayList<String> statuses = Controller.getInstance().getStatusOfBizType(bizType,langName);
		int index=0;
		for(String status : statuses){
			//sb.append("<li id='list_"+status+"'>"+status+"<a href='' onclick='removeItem(list_"+status+"); return false;'>     remove</a></li>");
			out.println("<li id='list1_"+index+"' value='list_"+HTMLEntities.htmlentities(status)+"'>"+HTMLEntities.htmlentities(status).replace('_', ' ')+"<a href='' onclick='removeItem(list1_"+index+"); return false;'>     remove</a></li>");
			index++;
		}
		//req.getSession().setAttribute("messageBizType", Controller.getInstance().getMessageOfBizType(bizType));

	}
}
